import { useEffect, useState } from "react";

const VersionCheck = () => {

  const [currentVersion, setCurrrentVersion] = useState();
  // const [setNextVersion] = useState();

  const get = async () => {
    const response = await fetch('../../public/version.json');
    const data = await response.json();
    // console.log('data',data);
    setCurrrentVersion(data.version)
  }

  const compare = async () => {
    const response = await fetch('../../public/version.json');
    const data = await response.json();
    // setNextVersion(data.version);
    console.log('data.version',data.version,'currentVersion',currentVersion);
    

    if (currentVersion !== data.version) {
      console.log('version有更新');

    }else{
      console.log('verion未更新。。');
      
    }
  }
  useEffect(() => {
    get();

    let timer: number | null = setInterval(() => {
      compare();
    }, 1000 * 60);

    return () => {
      timer && clearInterval(timer);
      timer = null
    }

  }, [currentVersion])

  return null

}

export default VersionCheck;